package com.sanyang.lawyer.service.Audit;

import com.sanyang.lawyer.ResultApi.ResponseResult;
import com.sanyang.lawyer.entity.Audit;
import com.sanyang.lawyer.entity.Case_audit;
import com.sanyang.lawyer.entity.Case_law;
import com.sanyang.lawyer.mapper.audit.Case_auditMapper;
import org.activiti.engine.task.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class Case_auditService {
    
    @Autowired
    private Case_auditMapper auditMapper;

    //添加一条数据
    public void insertOne(String processid,Case_audit audit){
        Case_audit case_audit1  = new Case_audit();
        Case_law law = new Case_law();
        
        Audit insertAudit = new Audit();
        insertAudit.setAuditid(processid);  //设置流程id
        law.setCaseId(audit.getCaseid().getCaseId()); //设置案件id
        
        case_audit1.setCaseid(law);
        case_audit1.setAuditid(insertAudit);
        
        auditMapper.insertOne(case_audit1);
    }

    //根据任务集合查询出所有的待办
    public List<Case_audit> findAuditByTask(List<Task> tasks){
        if(tasks.size()>0){
            String [] values = new String[tasks.size()];
            for(int i = 0; i< tasks.size(); i++){
                //获取流程id
                values[i] = tasks.get(i).getProcessInstanceId();
            }
            return auditMapper.findAuditByTask(values);
        }else{
            return null;
        }
    }


    //根据登录用户查询这个用户的流程申请
    public List<Case_audit> findApplyByUserid(Case_audit audit){
        return auditMapper.findApplyByUserid(audit);
    }
    
    
    
    
}
